package com.zhuiyun.pm.client.order.controller;

import com.zhuiyun.pm.client.order.entity.ClientOrder;
import com.zhuiyun.pm.client.order.service.OrderService;
import com.zhuiyun.pm.client.order.service.servicelmpl.OrderServiceImpl;
import com.zhuiyun.pm.config.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName AddressController
 * Description T0D0
 * Author Administrator
 * @Date 2023/3/14
 * Version 1.0
 **/
@RestController
@RequestMapping("order")
@CrossOrigin
public class OrderController {

    @Autowired
    OrderServiceImpl orderServiceImpl;

    @Autowired
    OrderService orderService;
    /**
     * 查询全部订单
     * @author 温
     * @date 2023/3/14 19:59
     * @parameter [clientAddress]
     * @return com.zhuiyun.pm.config.CommonResult
     */
    @GetMapping("/orderListInfo")
    public CommonResult orderListInfo(ClientOrder clientAddress) {
        List<ClientOrder> clientOrders = orderServiceImpl.orderListInfo(clientAddress);
        return CommonResult.ok(clientOrders);
    }

/**
 * 根据订id查询订单订单详情
 * @author 温
 * @date 2023/3/15 10:05
 * @parameter [clientOrder]
 * @return com.zhuiyun.pm.config.CommonResult
 */
    @GetMapping("/clientToBePaid/{id}")
  public CommonResult clientToBePaid(@PathVariable("id") int id) {
        ClientOrder clientOrder = orderServiceImpl.clientOrder(id);
        return CommonResult.ok(clientOrder);
    }
    /**
     * 两表连查查询地址详情
     * @author 温
     * @date 2023/3/17 10:52
     * @parameter [clientOrder]
     * @return com.zhuiyun.pm.config.CommonResult
     */
    @GetMapping("/clientList/{id}")
    public CommonResult clientList(@PathVariable("id") int id){
        ClientOrder clientOrders = orderServiceImpl.clientList(id);
        return CommonResult.ok(clientOrders);
    }

    /**
     * 点击立即付款 订单状态为2 到 待发货中
     * @author 温
     * @date 2023/3/15 10:23
     * @parameter [id]
     * @return com.zhuiyun.pm.config.CommonResult
     */
    @GetMapping("/clientPaid{id}")
    public CommonResult clientPaid (@PathVariable("id") Integer id){
        CommonResult commonResult = orderServiceImpl.clientPaid(id);
        return commonResult;
    }


    /**
     * 订单状态2发货以后 改变订单状态为3 到 待收货中
     * @author 温
     * @date 2023/3/15 10:23
     * @parameter [id]
     * @return com.zhuiyun.pm.config.CommonResult
     */
    @PostMapping("/clientCrops/{id}")
    public CommonResult clientCrops (@PathVariable("id")int id){
        CommonResult commonResult = orderServiceImpl.clientCrops(id);
        return commonResult;
    }


    /**
     * 订单状态3 点击收货完成 改变订单状态为4 到 收货完成中
     * @author 温
     * @date 2023/3/15 10:23
     * @parameter [id]
     * @return com.zhuiyun.pm.config.CommonResult
     */
    @GetMapping("/clientGoods/{id}")
    public CommonResult clientGoods (@PathVariable("id") int id){ // 路径拼接id用@PathVariable注解
        CommonResult commonResult = orderServiceImpl.clientGoods(id);
        return commonResult;
    }
}